﻿using System.Configuration;

namespace SimpleORM
{
    public class DataSourceElement : ConfigurationElement
    {
        #region Fields

        private const string stringDataSourceName = "name";
        private const string stringDataSourceType = "type";

        #endregion

        #region Properties

        [ConfigurationProperty(stringDataSourceName)]
        public string Name
        {
            get { return (string)this[stringDataSourceName]; }
            set { this[stringDataSourceName] = value; }
        }

        [ConfigurationProperty(stringDataSourceType)]
        public string Type
        {
            get { return (string)this[stringDataSourceType]; }
            set { this[stringDataSourceType] = value; }
        }

        #endregion
    }

    public class DataSourceElementCollection : ConfigurationElementCollection
    {
        #region Properties

        public DataSourceElement this[int index]
        {
            get { return (DataSourceElement)BaseGet(index); }
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }

        protected override string ElementName
        {
            get { return stringDataSource; }
        }

        #endregion

        #region Fields

        private const string stringDataSource = "add";

        #endregion

        #region Methods

        protected override ConfigurationElement CreateNewElement()
        {
            return new DataSourceElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return (element as DataSourceElement).Name;
        }

        #endregion
    }
}
